package beast.util;

import test.beast.BEASTTestCase;
import beast.evolution.alignment.Alignment;

/**
 * @author Kuangyu Wang
 */

public class testXMLParser extends BEASTTestCase {
	public void testTreeParser() throws Exception {
		Alignment aligned_seq = getAlignment();

		// The tree we specified:
		// ((((bonobo :0.1, gorilla :0.2):1, chimp :0.3):2,(orangutan:0.4,
		// siamang:0.5):0.2):0, human:0.6);

		// The sequence order in the alignment:
		// human:1
		// chimp:2
		// bonobo:3
		// gorilla:4
		// orangutan:5
		// siamang:6

		String newick = "((((3:0.1,4:0.2):0.1,2:0.3):0.2,(5:0.4,6:0.5):0.2):0,1:0.6)";
		TreeParser treeParser = new TreeParser();
		treeParser.m_oNewick.setValue(newick, treeParser);
		treeParser.m_oData.setValue(aligned_seq, treeParser);
		treeParser.initAndValidate();

		int leafNum = treeParser.getLeafNodeCount();
		for (int i = 0; i < leafNum; i++) {
			if (treeParser.getNode(i).isLeaf()) {
				System.out.println("The number is:" + i + " and the ID is: "
						+ treeParser.getNode(i).getID()
						+ " and the branch length is: "
						+ treeParser.getNode(i).getLength());
			}
		}
	}
}